Distance
Transpose notes by intervals and find distances between notes
Example
import * as Distance from "tonal-distance"
Distance.interval("C3", "C4")
Example
import { interval, semitones, transpose } from "tonal-distance"
semitones("C" ,"D")
interval("C4", "G4")
transpose("C4", "P5")
Example
const Tonal = require("tonal");
Tonal.Distance.transpose("C4", "P5")
Tonal.Distance.transposeBy("P5", "C4")
Distance.transpose(note, interval)
⇒ String
Transpose a note by an interval. The note can be a pitch class.
This function can be partially applied.
Kind: static method of Distance
Returns: String
- the transposed note
Param | Type |
---|
note | String |
interval | String |
Example
import { tranpose } from "tonal-distance"
transpose("d3", "3M")
transpose("D", "3M")
["C", "D", "E", "F", "G"].map(transpose("M3)) // => ["E", "F#", "G#", "A", "B"]
Distance.trFifths(pitchClass, fifhts)
⇒ String
Transpose a pitch class by a number of perfect fifths.
It can be partially applied.
Kind: static method of Distance
Returns: String
- the transposed pitch class
Param | Type | Description |
---|
pitchClass | String | the pitch class |
fifhts | Integer | the number of fifths |
Example
import { trFifths } from "tonal-transpose"
[0, 1, 2, 3, 4].map(trFifths("C"))
Distance.trFifths("G4", 1)
Distance.fifths(to, from)
Get the distance in fifths between pitch classes
Can be partially applied.
Kind: static method of Distance
Param | Type | Description |
---|
to | String | note or pitch class |
from | String | note or pitch class |
Distance.transposeBy(note, interval)
⇒ String
The same as transpose with the arguments inverted.
Can be partially applied.
Kind: static method of Distance
Returns: String
- the transposed note
Param | Type |
---|
note | String |
interval | String |
Example
import { tranposeBy } from "tonal-distance"
transposeBy("3m", "5P")
Distance.add(interval1, interval2)
⇒ String
Add two intervals
Can be partially applied.
Kind: static method of Distance
Returns: String
- the resulting interval
Param | Type |
---|
interval1 | String |
interval2 | String |
Example
import { add } from "tonal-distance"
add("3m", "5P")
Distance.subtract(minuend, subtrahend)
⇒ String
Subtract two intervals
Can be partially applied
Kind: static method of Distance
Returns: String
- interval diference
Param | Type |
---|
minuend | String |
subtrahend | String |
Distance.interval(from, to)
⇒ String
Find the interval between two pitches. It works with pitch classes
(both must be pitch classes and the interval is always ascending)
Can be partially applied
Kind: static method of Distance
Returns: String
- the interval distance
Param | Type | Description |
---|
from | String | distance from |
to | String | distance to |
Example
import { interval } from "tonal-distance"
interval("C2", "C3")
interval("G", "B")
Example
import * as Distance from "tonal-distance"
Distance.interval("M2", "P5")
Distance.semitones(from, to)
⇒ Integer
Get the distance between two notes in semitones
Kind: static method of Distance
Returns: Integer
- the distance in semitones or null if not valid notes
Param | Type | Description |
---|
from | String | Pitch | first note |
to | String | Pitch | last note |
Example
import { semitones } from "tonal-distance"
semitones("C3", "A2")
Tonal.Distance.semitones("C3", "G3")